package com.dmzc.stage1.chapter5;


import java.util.concurrent.TimeUnit;

public class SychronizedDefect {
    public synchronized void syncMethod(){
        try {
            TimeUnit.HOURS.sleep(5);
            System.out.println("执行了run");
        } catch (InterruptedException e) {
            //t1.interrupt()之后，t1不会释放monitor锁
            //t2处于timed_watting状态
            e.printStackTrace();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        SychronizedDefect defect=new SychronizedDefect();
        Thread t1=new Thread(defect::syncMethod,"T1");
        t1.start();
        TimeUnit.MILLISECONDS.sleep(2);
        Thread t2=new Thread(defect::syncMethod,"T2");
        t2.start();
        t1.interrupt();
    }
}
